package com.imooc.ad.controller;


import com.alibaba.fastjson.JSON;
import com.imooc.ad.exception.AdException;
import com.imooc.ad.service.IAdUnitService;
import com.imooc.ad.vo.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

//处理推广单元及相关服务
@Slf4j
@RestController
public class AdUnitOPController {
    //与IAdUnitService中的方法对应
    private final IAdUnitService adUnitService;

    @Autowired
    public AdUnitOPController(IAdUnitService adUnitService) {
        this.adUnitService = adUnitService;
    }
    //创建
    @PostMapping("/create/adUnit")
    public AdUnitResponse createUnit(@RequestBody AdUnitRequest request)
            throws AdException{
        log.info("ad-sponsor: createUnit ->{}", JSON.toJSONString(request));
        return adUnitService.createUnit(request);
    }
    @PostMapping("/create/unitKeyword")
    public AdUnitKeywordResponse createUnitKeyword(@RequestBody AdUnitKeywordRequest request)
        throws AdException {
        log.info("ad-sponsor: createKeyword -> {}", JSON.toJSONString(request));
        return adUnitService.createUnitKeyword(request);
    }
    @PostMapping("/create/unitIt")
    public AdUnitItResponse createUnitIt(@RequestBody AdUnitItRequest request)
            throws AdException {
        log.info("ad-sponsor: createUnitIt -> {}", JSON.toJSONString(request));
        return adUnitService.createUnitIt(request);
    }
    @PostMapping("/create/district")
    public AdUnitDistrictResponse createDistrict(@RequestBody AdUnitDistrictRequest request)
        throws AdException{
        log.info("ad-sponsor: createDistrict -> {}", JSON.toJSONString(request));
        return  adUnitService.createUnitDistrict(request);
    }
    @PostMapping("/create/creativeUnit")
    public CreativeUnitResponse createCreativeUnit(@RequestBody CreativeUnitRequest request)
            throws AdException{
        log.info("ad-sponsor: createCreativeUnit ->",JSON.toJSONString(request));
        return adUnitService.createCreativeUnit(request);
    }




/*    //获取
    @PostMapping("/get/adUnit")
    public List<AdUnit> getUnit(AdUnitRequest request) throws AdException {
        log.info("ad-sponsor: getUnit -> {}", JSON.toJSONString(request));
        return adUnitService.createUnit(request);
    }
    //更新
    @PostMapping("/update/adUnit")
    public AdUnitResponse updateUnit(@RequestBody AdUnitRequest request) throws AdException{
        log.info("ad-sponsor: update ->{}",JSON.toJSONString(request));
        return adUnitService.createUnit(request);
    }
    //删除
    @DeleteMapping("/delete/adUnit")
    public void deleteUnit(@RequestBody AdUnitRequest request) throws AdException{
        log.info("ad-sponsor : deleteUnit -> {}",JSON.toJSONString(request));
        adUnitService.
    }*/

}
